﻿using System;
using Beaker;
using OpenCube.Nbt.Mapping;

namespace OpenCube.Model.Primitives.Converters
{
	/// <summary>
	/// Converts a double in that represents seconds to <see cref="TimeSpan"/> and back.
	/// </summary>
	public sealed class TimeSpanSecondsConverter
		: NbtSimpleTypeConverter<TimeSpan, double>
	{
		protected override TimeSpan ConvertToModelValue(double nbtValue)
		{
			return TimeSpan.FromSeconds(nbtValue);
		}

		protected override Maybe<double> ConvertToNbtValue(TimeSpan modelValue)
		{
			return modelValue.TotalSeconds;
		}
	}
}